<template>
	<view style="padding: 20rpx;height: 100%;">
		<view class="display_flex u-m-b-20">
			<view class="u-flex-1">
				<el-button type="primary" size="mini" @click="show1 = true" class="u-m-l-20">
					新增画作
				</el-button>
			</view>

			<view class="display_flex u-flex-2">
				<el-input placeholder="请输入内容" v-model="params.searchText" @change="confirmSearch" class="u-m-l-20"
					size="mini" />

				<el-switch v-model="params.isNice" active-text="精选内容" inactive-text="" class="u-m-l-20"
					@change="confirmSearch" />
			</view>
		</view>

		<view class="u-padding-20 bgfff" style="height: calc(100% - 100rpx);width: 100%;">
			<el-table :data="dataList" style="width: 100%" stripe border size="mini" height="95%">
				<el-table-column type="index" width="50" label="序号"/>
				<el-table-column prop="number" label="编号" width="150"/>
				
				<el-table-column prop="nameZh" label="主要描述" />
				<el-table-column prop="price" label="价格" width="150"/>
				<el-table-column prop="downLoadNum" label="下载次数" width="150"/>
				<el-table-column prop="createdAt" label="创建日期" width="180"/>
				
				
				<el-table-column fixed="right" label="操作" width="150" align="center">
					<template slot-scope="scope">
						<el-button @click="deleteThis(scope.row)" type="text" size="small">删除</el-button>
						<el-button type="text" size="small" @click="editThis(scope.row)">编辑</el-button>
					</template>
				</el-table-column>
			</el-table>
			<view class="u-text-right bgfff u-padding-20">
				<el-pagination @current-change="handleCurrentChange" small :current-page="params.pageNum"
					:page-sizes="[20, 40, 60,80,100]" :page-count="maxPage"
					layout="total, sizes, prev, pager, next, jumper" :total="maxCount">
				</el-pagination>
			</view>
		</view>

		<paintEdit v-if="show1" @save="show1 = false,chooseItem='',getData()" :detail="chooseItem"
			@close="show1 = false,chooseItem = ''" />
	</view>
</template>

<script>
	import paintEdit from '@/components/paintEdit'
	let that
	export default {
		components: {
			paintEdit
		},
		data() {
			return {
				show1: false,
				chooseItem: '',
				dataList: [],
				maxCount: 1,
				maxPage: 1,

				params: {
					pageSize: 20,
					pageNum: 1,
					searchText: '',
					isNice: false,
				}
			}
		},

		onLoad() {
			that = this
			that.getData()
		},

		methods: {
			deleteThis(item) {
				uni.showModal({
					content: "是否删除此条目",
					success(res) {
						if (res.confirm) {
							that.$http.Post("admin/artPainting/remove", {
								objectId: item.objectId
							}, "加载中...").then(res => {
								that.getData()
							})
						}
					}
				})
			},

			confirmSearch() {
				that.dataList = []
				that.params.pageNum = 1
				that.getData()
			},

			editThis(item) {
				this.chooseItem = item
				this.show1 = true
			},

			handleCurrentChange(value) {
				that.params.pageNum = value
				that.getData()
			},

			getData() {
				this.$http.Post("admin/artPainting/list", that.params, "加载中...").then(res => {
					this.dataList = res.data
					that.maxCount = res.maxCount
					that.maxPage = res.maxPage
				})
			}
		}
	}
</script>

<style>

</style>
